More Related Content Similar to computer notes - Data Structures - 4 Similar to computer notes - Data Structures - 4 (20) More from ecomputernotes (18) computer notes - Data Structures - 41. Class No.04 Data Structures http://ecomputernotes.com 2. C++ Code for Linked List // position current before the first // list element void start() { lastCurrentNode = headNode; currentNode = headNode; }; http://ecomputernotes.com 3. C++ Code for Linked List void remove() { if( currentNode != NULL && currentNode != headNode) { lastCurrentNode->setNext(currentNode->getNext()); delete currentNode; currentNode = lastCurrentNode->getNext(); size--; } }; 2 6 7 1 headNode currentNode size=5 lastcurrentNode 8 http://ecomputernotes.com 4. C++ Code for Linked List void remove() { if( currentNode != NULL && currentNode != headNode) { lastCurrentNode->setNext(currentNode->getNext()); delete currentNode; currentNode = lastCurrentNode->getNext(); size--; } }; 2 6 7 1 headNode currentNode size=5 lastcurrentNode 8 1 1 http://ecomputernotes.com 5. C++ Code for Linked List void remove() { if( currentNode != NULL && currentNode != headNode) { lastCurrentNode->setNext(currentNode->getNext()); delete currentNode; currentNode = lastCurrentNode->getNext(); size--; } }; 2 7 1 headNode currentNode size=5 lastcurrentNode 8 1 1 2 2 http://ecomputernotes.com 6. C++ Code for Linked List void remove() { if( currentNode != NULL && currentNode != headNode) { lastCurrentNode->setNext(currentNode->getNext()); delete currentNode; currentNode = lastCurrentNode->getNext(); size--; } }; 2 7 1 headNode currentNode size=4 lastcurrentNode 8 1 1 2 2 3 3 4 4 http://ecomputernotes.com 7. C++ Code for Linked List int length() { return size; }; private: int size; Node *headNode; Node *currentNode, *lastCurrentNode; http://ecomputernotes.com 8. Example of List Usage #include <iostream> #include <stdlib.h> #include "List.cpp" int main(int argc, char *argv[]) { List list; list.add(5); list.add(13); list.add(4); list.add(8); list.add(24); list.add(48); list.add(12); list.start(); while (list.next()) cout << "List Element: "<< list.get()<<endl; } http://ecomputernotes.com 16. Doubly-Linked List Node class Node { public: int get() { return object; }; void set(int object) { this->object = object; }; Node* getNext() { return nextNode; }; void setNext(Node* nextNode) { this->nextNode = nextNode; }; Node* getPrev() { return prevNode; }; void setPrev(Node* prevNode) { this->prevNode = prevNode; }; private: int object; Node* nextNode; Node* prevNode; }; http://ecomputernotes.com Editor's Notes The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future. End of lecture 4. The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.